package com.wkf.calculator.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
//检查是否有小括号
public class CheckExtraSymbol {
    //public String tmpOld;
    public String tmp;

//    public String getTmpOld() {
//        return tmpOld;
//    }
    public String getTmp(){
        return tmp;
    }

    public CheckExtraSymbol(String tmp){
        //this.tmpOld = tmp;
        this.tmp = tmp;
    }

    public ArrayList<ArrayList<Integer>> checkIs(){
        ArrayList<Integer> positionOne = new ArrayList<>();
        ArrayList<Integer> positionTwo = new ArrayList<>();
        ArrayList<ArrayList<Integer>> positionContain = new ArrayList<>();
        //int a = 0;
        for (int i = 0; i < tmp.length(); i++) {
            char c = tmp.charAt(i);
            if (c == 40) {
                positionOne.add(i);

            } else if (c == 41) {
                positionTwo.add(i);
            }
        }
        positionContain.add(positionOne);
        positionContain.add(positionTwo);
        return positionContain;
    }
    public ArrayList<String> cutTmp(){
        String tmpUnit = "";
        String tmpBig = "";
        ArrayList<String> tmpList = new ArrayList<String>();
        for (int i = 0; i < checkIs().get(0).size(); i++){
            for (Integer j = checkIs().get(0).get(i); j < checkIs().get(1).get(i); j++){
                    tmpUnit += tmp.charAt(j);
                    tmpBig += tmpUnit;
                    tmpUnit = "";
            }
            tmpBig.replace("(","");
            tmpList.add(tmpBig);
            tmpBig = "";
        }

        return tmpList;
    }
    public void insertBack(ArrayList backNumList){

        for (int i = 0; i < cutTmp().size(); i++) {
            tmp = tmp.replace(cutTmp().get(i),backNumList.get(i).toString());
        }
        tmp = tmp.replace("(","");
        tmp = tmp.replace(")","");
    }

}
